<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
</head>

<body>
  <h1>发送axios请求</h1>
  <button class="btn1">发送axios里的get形式请求</button>
  <button class="btn2">发送axios里的post形式请求</button>
  <script>
    // axios会对外暴露一个axios对象
    // console.log(axios);
    // 引入axios
    document.querySelector(".btn1").onclick = async function () {
      // axios({
      //   url: "/getdata",
      //   method: "get",  // 默认请求是get方式
      //   params: {
      //     x: 1,
      //     y: 2
      //   }
      // }).then(res => {
      //   let { data } = res;
      //   console.log(data);
      // })
      // await改写 注意上面的函数需要加上async
      let { data } = await axios({
        url: "/getdata",
        method: "get",  // 默认请求是get方式
        params: {
          x: 1,
          y: 2
        }
      })
      console.log(data);
    }

    function fn () {
      console.log("fn");
    }
    fn();
    // mixin 混入模式
    fn.hello = "你好";
    console.log(fn);

    document.querySelector(".btn2").onclick = function () {
      axios({
        url: "/postdata",
        method: "post",
        data: {
          x: 3,
          y: 4
        }
        // data:"x=3,y=4";
      }).then(res => {
        let { data } = res;
        console.log(data);
      })
    }
  </script>
</body>

</html>